package com.hockeo.client.model;

import com.google.gwt.user.client.ui.AbstractImagePrototype;

/**
 * Simple data object which is targeted at non-remote client side objects that need to be
 * rendered with a name and optionally an icon.
 *
 * @version $Id$
 * @author janjanke
 */
@SuppressWarnings( "serial" )
public class JSSimpleData extends JSData
{
  public static final String PARAM_LABEL           = "js_label";
  public static final String PARAM_ICON            = "js_icon";
  public static final String PARAM_PARENT_ID       = "js_parent_id";

  public JSSimpleData( String strId )
  {
    this( strId, null, null, false );
  }

  public JSSimpleData( String strId, String strLabel )
  {
    this( strId, strLabel, null, false );
  }

  public JSSimpleData( String strId, String strLabel, AbstractImagePrototype icon )
  {
    this( strId, strLabel, icon, false );
  }

  public JSSimpleData( String strId, String strLabel, AbstractImagePrototype icon, boolean fRemoteChildren )
  {
    set( PARAM_ID, strId );

    if ( strLabel != null )
      set( PARAM_LABEL, strLabel );

    if ( icon != null )
      set( PARAM_ICON, icon );

    set( PARAM_REMOTE_CHILDREN, fRemoteChildren );
  }

  public void setParentId( String str )
  {
    set( PARAM_PARENT_ID, str );
  }

  public String getParentId()
  {
    return getString( PARAM_PARENT_ID );
  }

  /**
   * Overridden to return null and to indicate that this is not a server side backed
   * entity.
   */
  @Override
  public String getServerClass()
  {
    return null;
  }

  public String getLabel()
  {
    return getString( PARAM_LABEL );
  }

  public AbstractImagePrototype getIcon()
  {
    return (AbstractImagePrototype) get( PARAM_ICON );
  }

  @Override
  public String toString()
  {
    return getLabel();
  }
}
